package com.gsit.expenditure.domain;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.format.annotation.DateTimeFormat;
import com.gsit.expenditure.utils.BillStatus;

@Entity
@Table(name = "bill")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE )
@DiscriminatorColumn(name = "TYPE", discriminatorType=DiscriminatorType.STRING, length=20)
@NamedQueries({@NamedQuery (name= "Bill.findAll",query= "select b from Bill b where b.status = :status ")})
public class Bill extends BaseEntity {                            

	@ManyToOne(optional = true , cascade = CascadeType.ALL)
	@JoinColumn(name="customer_id")
	private Customer customer;	
	
	@ManyToOne(optional = true , cascade = CascadeType.ALL)
	@JoinColumn(name="vehicle_id")
	private Vehicle vehicle;
	
	
	@NotNull(message="Reference Number Required")
	@NotEmpty(message="Reference Number Required")
	
	@Column(name = "referenceNumber")
	private String referenceNumber;
	
	@DateTimeFormat
	@NotNull(message="Date Required")
	@Column(name = "billDate", nullable=true)
	@Temporal(TemporalType.DATE)
	private Date billDate;
	
	@Min(value=1,message="Should be greater than or equal to 1")
	@Column(name = "amount")
	private Double amount;
	
	@Column(name="status")
	@Enumerated(EnumType.STRING)
	private BillStatus status;
	
	@ManyToOne(optional = true , cascade = CascadeType.ALL)
	@JoinColumn(name="invoice_id")
	private Invoice invoice;
	

	@Transient
    private Boolean select = Boolean.FALSE;
	
	
	public Boolean getSelect() {
		return select;
	}

	public void setSelect(Boolean select) {
		this.select = select;
	}
	
	public Invoice getInvoice() {
		return invoice;
	}

	public void setInvoice(Invoice invoice) {
		this.invoice = invoice;
	}


	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public Vehicle getVehicle() {
		return vehicle;
	}

	public void setVehicle(Vehicle vehicle) {
		this.vehicle = vehicle;
	}

	public String getReferenceNumber() {
		return referenceNumber;
	}

	public void setReferenceNumber(String referenceNumber) {
		this.referenceNumber = referenceNumber;
	}

	public Double getAmount() {
		return amount;
	}

	public void setAmount(Double amount) {
		this.amount = amount;
	}



	public BillStatus getStatus() {
		return status;
	}


	public void setStatus(BillStatus status) {
		this.status = status;
	}


	public Date getBillDate() {
		return billDate;
	}


	public void setBillDate(Date billDate) {
		this.billDate = billDate;
	}

	@Override
	public String toString() {
		return "Bill [customer=" + customer + ", vehicle=" + vehicle
				+ ", referenceNumber=" + referenceNumber + ", billDate="
				+ billDate + ", amount=" + amount + ", status=" + status
				+ ", invoice=" + invoice + ", select=" + select + ", getId()="
				+ getId() + ", getCreatedDate()=" + getCreatedDate()
				+ ", getModifiedDate()=" + getModifiedDate()
				+ ", getVersion()=" + getVersion() + ", getClass()="
				+ getClass() + ", hashCode()=" + hashCode() + ", toString()="
				+ super.toString() + "]";
	}


}
